//
//  Kylin_NavigationViewController.m
//  01-LotteryBaseFrame
//
//  Created by Kylin on 16/1/4.
//  Copyright © 2016年 kylin. All rights reserved.
//

#import "Kylin_NavigationViewController.h"

@interface Kylin_NavigationViewController ()<UIGestureRecognizerDelegate>

@end

@implementation Kylin_NavigationViewController

// 当当前类, 或者其子类第一次使用的时候调用
// 初始化这个类
+ (void)initialize{
    
    // 导航条标识
    // 整个工程的导航条标识 appearance
    
    // 该方法已过期
//    UINavigationBar *bar = [UINavigationBar appearanceWhenContainedIn:self, nil];
    
    // 该方法防止子类调用时初始化多次调用
    if (self == [Kylin_NavigationViewController class]) {

    // 该方法返回一个数组,可以定义多个 类使用该方法
    UINavigationBar *bar = [UINavigationBar appearanceWhenContainedInInstancesOfClasses:@[[Kylin_NavigationViewController class]]];
    
       //设置导航条背景图片
    [bar setBackgroundImage:[UIImage imageNamed:@"NavBar64"] forBarMetrics:UIBarMetricsDefault];
 
    // 设置字体属性
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    // 设置字体颜色
    dict[NSForegroundColorAttributeName] = [UIColor whiteColor];
    // 设置字体大小
    dict[NSFontAttributeName] = [UIFont boldSystemFontOfSize:22];
    
    [bar setTitleTextAttributes:dict];
        
    // 把返回按钮也设置成白色
    bar.tintColor = [UIColor whiteColor];
        
    // 移交返回按钮的文字
    UIBarButtonItem *item = [UIBarButtonItem appearanceWhenContainedInInstancesOfClasses:@[self]];
      
     // 改变position的位置,让view看不到 让水平位置高UIBarButtonItem
    [item setBackButtonTitlePositionAdjustment:UIOffsetMake(0, - 64) forBarMetrics:UIBarMetricsDefault];
    
    }
}


/**
 *   重写系统方法,增加自定义
 */
- (void)viewDidLoad {
    [super viewDidLoad];

    // 获取当前交互pop手势
    UIGestureRecognizer *gesure = self.interactivePopGestureRecognizer;
    
    
    NSArray *targets = [gesure valueForKeyPath:@"_targets"];
    
    // 取出target
    id target = [targets[0] valueForKeyPath:@"target"];
    
    // 禁止系统的
    self.interactivePopGestureRecognizer.enabled = NO;
    
    // 仿系统做法
    UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc]initWithTarget:target action:@selector(handleNavigationTransition:)];
    
    [self.view addGestureRecognizer:pan];
    
    pan.delegate = self;
    
    
}

- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer{
    
    // 非根控制器就可以进行交互
    return  self.childViewControllers.count > 1;
    
}

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{
    
    
    // 当前viewController是目标控制器
    if (self.childViewControllers.count > 0) {
        // 非根控制器就隐藏下面的tabar
        viewController.hidesBottomBarWhenPushed = YES;
//        NSLog(@"%@",viewController);
    }
    
    [super pushViewController:viewController animated:animated];
}



@end
